let mysql = require('mysql');
let msyql_config = require('../../config/mysql.json');
let pool = mysql.createPool(msyql_config);

let db = {};

db.query = function (sql, params) {

  return new Promise((resolve, reject) => {
    // 取出连接
    pool.getConnection(function (err, connection) {

      if (err) {
        reject(err);
        return;
      }
      connection.query(sql, params, function (error, results, fields) {
        console.log(`${ sql }=>${ params }`);
        // 释放连接
        connection.release();
        if (error) {
          reject(error);
          return;
        };
        resolve(results);
      });
    });
  });
};
module.exports = db;


